package com.docman.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import com.docman.dbconnect.ConnectionManager;
import com.docman.domainmodel.TagBean;

public class TagDAO {

	
	static Connection currentCon = null;
	static ResultSet rs = null;
	
	
	public static ArrayList<TagBean> getTags() {
		ArrayList<TagBean> tags = new ArrayList<TagBean>();
		
		
		String query = "SELECT * FROM TAG";
		try{
			
			currentCon =ConnectionManager.getInstance().getConnection();
			Statement stmt  = currentCon.prepareStatement(query);
			
			rs= stmt.executeQuery(query);
			
			while(rs.next()){
				TagBean tag = new TagBean();
				
				tag.setTagId(rs.getInt("TAGID"));
				tag.setTagName(rs.getString("TAGNAME"));
				
				tags.add(tag);
				
			}
			
			rs.close();
			stmt.close();
		}
		
		catch(Exception e){
			System.out.println("Error while getting tags from db "+ e);
		}
		
		return tags;
	
	}
	
}
